/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.unal.bioingenium.kbmed.knowledge.similarity.metrics;

import co.edu.unal.bioingenium.kbmed.knowledge.hierarchy.HierarchyService;
import co.edu.unal.bioingenium.kbmed.util.math.UtilMath;

/**
 *
 * @author Alejandro Riveros Cruz
 * simlch(c1,c2)=-log(p/(2*depth))
 * Where:
 *   p = |shortestPath(c1,c2)|
 *   depth = maximum depth of the hierarchy
 */
public class LCH implements SemanticSimilarity {

    private HierarchyService graphManager;

    /**
     * 
     */
    public LCH() {
        this.graphManager = HierarchyService.getInstance();
    }

    /**
     * 
     * @param conceptId1
     * @param conceptId2
     * @param category
     * @return
     */
    @Override
    public float getSimilarity(String conceptId1, String conceptId2, String category) {
        int depth = graphManager.getHierarchy(category).getHierachyDepth();
        int p = graphManager.getArtificialShortestPath(conceptId1, conceptId2, category).size() + 1;
        return -1 * UtilMath.log2((float) p / (float) (2 * depth));
    }
}
